﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FilStartUps.FILAPI;

namespace FilStartUps.Controls
{
    public partial class FilStartUps_Category : System.Web.UI.UserControl
    {
        //GETPAGESUB FUNCTION
        public void GetCategory(int id)
        {
            try
            {
                var cat = FilStartUpsAPI.GetPageSub(id);
               
                dlFilStartUps_Category.DataSource = cat;
                dlFilStartUps_Category.DataBind();
            }
            catch (Exception)
            {

            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int pageidPK = Convert.ToInt32(Request.QueryString["pg"].Trim());
               
                if (pageidPK != 0)
                {
                    GetCategory(pageidPK);
                }
            }
        }

        //LATESTPOST.aspx of Category;
        //Category.aspx:
        //FilStartUps_Category Control
        //FilStartUps_PageNav Control
        protected void dlFilStartUps_Category_ItemCommand(object sender, DataListCommandEventArgs e)
        {
            if (e.CommandName == "SelectRow")
            {
                LinkButton lnkcatname = (LinkButton)dlFilStartUps_Category.Items[e.Item.ItemIndex].FindControl("categoryname");
                Label lbcatidPK = (Label)dlFilStartUps_Category.Items[e.Item.ItemIndex].FindControl("catidPK");
                Label lbpageidFK = (Label)dlFilStartUps_Category.Items[e.Item.ItemIndex].FindControl("pageidFK");
                //Encrypt(lbcatidPK) ==> Option
                Server.Transfer("~/Category.aspx?c=" + lbcatidPK.Text + "&pg=" + lbpageidFK.Text);
            }
        }
    }
}